package me.jiatao.wan.data.database.dao

import androidx.paging.PagingSource
import androidx.room.Dao
import androidx.room.Insert
import androidx.room.OnConflictStrategy
import androidx.room.Query
import me.jiatao.wan.data.database.entity.ArticleEntity
import me.jiatao.wan.data.database.entity.ArticleType


/**
 * @Author: JiaTao
 * @CreateDate: 2021/8/29 10:21
 * @Version: 1.0
 * @Description:
 */

@Dao
interface ArticleDao {
    @Insert(onConflict = OnConflictStrategy.REPLACE)
    suspend fun insert(article: ArticleEntity)

    @Insert(onConflict = OnConflictStrategy.REPLACE)
    suspend fun insertList(articleList: List<ArticleEntity>)

    @Query("DELETE FROM ArticleEntity WHERE articleType = :type")
    suspend fun clear(type: ArticleType)

    @Query("SELECT * FROM ArticleEntity WHERE articleType = :type")
    fun getArticlePaging(type: ArticleType): PagingSource<Int, ArticleEntity>
}